package com.ruoyi.student_club.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.student_club.domain.FirstPoster;
import com.ruoyi.student_club.mapper.FirstPosterMapper;
import com.ruoyi.student_club.utils.UploadUtil;
import com.ruoyi.student_club.vo.FirstPosterVo;
import com.ruoyi.student_club.vo.app.FirstPagePosterVo;
import org.springframework.stereotype.Service;
import com.ruoyi.student_club.service.IFirstPosterService;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * 首页轮播图Service业务层处理
 * 
 * @author 无尤
 * @date 2022-01-14
 */
@Service
public class FirstPosterServiceImpl extends ServiceImpl<FirstPosterMapper, FirstPoster> implements IFirstPosterService {

    @Resource
    private FirstPosterMapper posterMapper;

    @Override
    public String uploadPoster(MultipartFile file) {
        String typeName = "firstPost";
        return UploadUtil.upload(file,typeName);
    }

    @Override
    public List getPoster() {
        List<FirstPoster> posterList = baseMapper
                .selectList(new QueryWrapper<FirstPoster>().orderByDesc("create_time"));
        List<FirstPosterVo> list = new ArrayList<>();
        for (FirstPoster firstPoster : posterList) {
            FirstPosterVo posterVo = new FirstPosterVo();
            BeanUtils.copyBeanProp(posterVo,firstPoster);
            list.add(posterVo);
        }
        return list;
    }

    /**
     * 获取首页轮播图
     * @return
     */
    @Override
    public List<FirstPagePosterVo> showPoster(){
        return posterMapper.getPagePosterList();
    }
}
